package com.ndbg.demo.service.sign.impl;



import com.ndbg.demo.model.sign.SilenceSealRequest;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Base64;

/**
 * @author chenXB
 * @createTime 2023年09月11日 14:09:00
 */
public class SignApiServiceImpl {
    private static String  url = "http://58.22.60.121:803/gateway/sdk/v1/api/execute";
    private static String appId = "d73dc93a9c2549748f5680b13fa748b1";
    private static String secret = "42d6dc8d7bc949b8a87e0e2cb281d5ae";
    private static String projectKey = "1699966592386859008";



//    public static void main(String[] args) {
//        SignHeadRequest signHeadRequest = new SignHeadRequest();
//        signHeadRequest.setAppId(appId);
//        signHeadRequest.setAppSecret(secret);
//        signHeadRequest.setUrl(url);
//        signHeadRequest.setProjectKey(projectKey);
//        ESignApi signApi = new ESignApi(signHeadRequest);
//        UploadFileRequest uploadFileRequest = new UploadFileRequest();
//        uploadFileRequest.setFileName("文件名称");
//        uploadFileRequest.setImgExt("pdf");
//        uploadFileRequest.setFileBase64(getImageBase64("C:\\Users\\Administrator\\Desktop\\e签临时文件\\测试图片.pdf"));
//        String data = signApi.execute(uploadFileRequest);
//        System.out.println(data);
//    }


//    public static void main(String[] args) {
//        SignHeadRequest signHeadRequest = new SignHeadRequest();
//        signHeadRequest.setAppId(appId);
//        signHeadRequest.setAppSecret(secret);
//        signHeadRequest.setUrl(url);
//        signHeadRequest.setProjectKey(projectKey);
//        ESignApi signApi = new ESignApi(signHeadRequest);
//        ApplyLongTermRequest applyLongTermRequest = new ApplyLongTermRequest();
//        applyLongTermRequest.setCertName("陈臣");
//        applyLongTermRequest.setCertType("1");
//        applyLongTermRequest.setCardNo("350128199610227922");
//        applyLongTermRequest.setPicData("");
//        applyLongTermRequest.setImgExt("PNG");
//        applyLongTermRequest.setPassword("123456");
//        String execute = signApi.execute(applyLongTermRequest);
//        System.out.println(execute);
//    }

//    public static void main(String[] args) {
//        SignHeadRequest signHeadRequest = new SignHeadRequest();
//        signHeadRequest.setAppId(appId);
//        signHeadRequest.setAppSecret(secret);
//        signHeadRequest.setUrl(url);
//        signHeadRequest.setProjectKey(projectKey);
//        ESignApi signApi = new ESignApi(signHeadRequest);
//        SilenceSealRequest silenceSealRequest = new SilenceSealRequest();
//        silenceSealRequest.setUserKey("1314123");
//        silenceSealRequest.setOrderNumber("202309120011");
//        silenceSealRequest.setFileId(1090L);
//        silenceSealRequest.setSilenceSessionId("40031c8959f9471f9a86a03de54e3752");
//        silenceSealRequest.setPassword("123456");
//        silenceSealRequest.setOperatorName("张三");
//        silenceSealRequest.setOperatorPhone("13478977656");
//        silenceSealRequest.setOperatorIdCard("350128199610227922");
//        silenceSealRequest.setUserRole("1");
//        List<SilenceSealRequest.sealInfo> sealInfoList = new ArrayList<>();
//        SilenceSealRequest.sealInfo sealInfo = new SilenceSealRequest.sealInfo();
////        sealInfo.setPagen("1-1");
////        sealInfo.setX("100");
////        sealInfo.setY("0");
//        sealInfo.setType("2");
//        sealInfo.setKeyWord("收款单位");
//        sealInfo.setOffsetX("100");
//        sealInfo.setOffsetY("100");
//        sealInfoList.add(sealInfo);
//        silenceSealRequest.setSealInfoList(sealInfoList);
//        signApi.execute(silenceSealRequest);
//    }

    //签章校验
//    public static void main(String[] args) {
//        SignHeadRequest signHeadRequest = new SignHeadRequest();
//        signHeadRequest.setAppId(appId);
//        signHeadRequest.setAppSecret(secret);
//        signHeadRequest.setUrl(url);
//        signHeadRequest.setProjectKey(projectKey);
//        ESignApi signApi = new ESignApi(signHeadRequest);
//        VerifySealRequest verifySealRequest = new VerifySealRequest();
//        verifySealRequest.setFileBase64(getImageBase64("C:\\Users\\Administrator\\Desktop\\e签临时文件\\1701475047098548224文件名称.pdf"));
//        verifySealRequest.setFileName("1701475047098548224文件名称");
//        verifySealRequest.setImgExt("pdf");
//        signApi.execute(verifySealRequest);
//    }

    //获取文件信息
//    public static void main(String[] args) {
//        SignHeadRequest signHeadRequest = new SignHeadRequest();
//        signHeadRequest.setAppId(appId);
//        signHeadRequest.setAppSecret(secret);
//        signHeadRequest.setUrl(url);
//        signHeadRequest.setProjectKey(projectKey);
//        ESignApi signApi = new ESignApi(signHeadRequest);
//        GetFileInfoRequest getFileInfoRequest = new GetFileInfoRequest();
//        getFileInfoRequest.setFileId("1100");
//        signApi.execute(getFileInfoRequest);
//    }

    //修改密码
    public static void main(String[] args) {

    }

    public static String getImageBase64(String filePath){
        try {
            // 将文件读取为字节数组
            byte[] pdfBytes = readPdfFile(filePath);
            // 使用Base64编码将字节数组转换为Base64字符串
            String base64 = Base64.getEncoder().encodeToString(pdfBytes);
            // 输出Base64字符串
//            System.out.println(base64);
            return base64;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    private static byte[] readPdfFile(String filePath) throws IOException {
        File file = new File(filePath);
        FileInputStream fis = new FileInputStream(file);
        byte[] data = new byte[(int) file.length()];
        fis.read(data);
        fis.close();
        return data;
    }
}
